#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2022/5/25 0:09
# @Author  : 刘广鸿
# @File    : __init__.py.py
# @Software: PyCharm

from flask import Flask
from app.dbs import db
import confing
from flask_migrate import Migrate
from app.models import models
from app.views.admin import admin_blu
from app.views.index import index_blu

"""
    快速切换配置，开发、测试与生产隔离
"""
Confing = {
    "dev": confing.DevelopmentConfig,
    "pro": confing.ProductionConfig,
    "test": confing.TestingConfig
}


def create_app(version):
    app = Flask(__name__)
    # 加载配置
    app.config.from_object(Confing.get(version))
    # 注册蓝图
    app.register_blueprint(admin_blu)
    app.register_blueprint(index_blu)
    db.init_app(app)  # 绑定db
    migrate = Migrate(app, db)  # 新版本只需这一句话即可
    """
    去到项目的根目录 可以直接执行命令 flask --help 
    
    首先你需要设置启动文件
    set FLASK_APP={启动文件}
    
    然后你就可以开始数据库迁移了
    flask db init
    flask db migrate -m "注释"
    flask db upgrade
    flask db downgrade
     
    """

    return app
